<template>
    <el-menu class="el-menu-vertical-demo" @open="handleOpen" @close="handleClose" :collapse="isCollapse"
        :default-openeds="openeds" 
        background-color="#ebeef2"
        text-color="#8f8787"
        active-text-color="#fbac91">
        <div class="mylogo">
            <img src="../assets/yunlogo.png" alt="yunlogo">
            <span>寻真云盘</span>
        </div>
        <el-menu-item @click="clickMenu(item)" v-for="item in noChild" :key="item.name" :index="item.name">
            <i :class="`el-icon-${item.icon}`"></i>
            <span slot="title">{{ item.label }}</span>
        </el-menu-item>

        <el-submenu v-for="item in hasChild" :key="item.label" :index="item.label">
            <template slot="title">
                <i :class="`el-icon-${item.icon}`"></i>
                <span slot="title">{{ item.label }}</span>
            </template>
            <el-menu-item-group  v-for="subitem in item.children" :key="subitem.name">
                <el-menu-item @click="clickMenu(subitem)" :index="subitem.label" >
                    <span slot="title">
                    <i :class="`el-icon-${subitem.icon}`"></i>

                        {{ subitem.label }}</span>
                </el-menu-item>
            </el-menu-item-group>
        </el-submenu>

    </el-menu>
</template>



<script>
export default {
    data() {
        return {
            openeds: ['文件分类'],
            isCollapse: false,
            menuData: [
                {
                    path: '/',
                    name: 'home',
                    label: '我的主页',
                    icon: 's-home',
                    url: 'Home/Home'
                },
                {
                    path: '/allfile',
                    name: 'allfile',
                    label: '全部文件',
                    icon: 'folder-opened',
                    url: 'AllFile/AllFile'
                },
                {
                    path: '/share',
                    name:'share',
                    label: '我的分享',
                    icon: 'share',
                    url:'Share/Share'
                },
                {
                    label: '文件分类',
                    icon: 'menu',
                    children: [
                        {
                            path: '/document',
                            name: 'document',
                            label: '文档',
                            icon: 'document',
                            url: 'Sort/document'
                        },
                        {
                            path: '/picture',
                            name: 'picture',
                            label: '图片',
                            icon: 'picture-outline',
                            url: 'Sort/picture'
                        },
                        {
                            path: '/audio',
                            name: 'audio',
                            label: '音频',
                            icon: 'service',
                            url: 'Sort/audio'
                        },
                        {
                            path: '/video',
                            name: 'video',
                            label: '视频',
                            icon: 'video-camera-solid',
                            url: 'Sort/video'
                        },
                        // {
                        //     path: '/compress',
                        //     name: 'compress',
                        //     label: '压缩包',
                        //     icon: 'collection',
                        //     url: 'Sort/compress'
                        // },
                    ]
                },
                {
                    path: '/recycle',
                    name: 'recycle',
                    label: '回收站',
                    icon: 'delete',
                    url: 'Recycle/Recycle'
                }
            ],
        };
    },
    methods: {
        handleOpen(key, keyPath) {
            console.log(key, keyPath);
        },
        handleClose(key, keyPath) {
            console.log(key, keyPath);
        },
        //点击菜单跳转导航路由
        clickMenu(item){
            //获取路由使用push跳转
            console.log(item.path)

            //判断当前路由与跳转路由是否一致 一致就不跳转
            if(this.$route.path != item.path && !(this.$route.path === '/home' && item.path === '/')){
                this.$router.push(item.path)
            }
        }
    },
    computed: {
        //过滤菜单数据无子时
        noChild() {
            return this.menuData.filter(item => !item.children)
        },
        hasChild() {
            return this.menuData.filter(item => item.children)
        }
    }
}
</script>

<style lang="less" scope>
.el-menu-vertical-demo:not(.el-menu--collapse) {
    span{
        font-size: 14px;
        font-weight:800;
        font-weight:bold;
    }
    .mylogo{
        img{
            vertical-align: middle;
            width: 70px;
            height: 70px;
        }
        span{
            vertical-align: middle;
            font-size:xx-large;
            color: #494949;
            text-align:center;
            font-weight: bold;
            font-family: 'Zhi Mang Xing';
        }
    }
    
}


</style>